/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * CuentaProveedores.java
 *
 * Created on 28/07/2011, 16:05:41
 */

package ventanas;

import conexiones.AdministradorDeConexiones;
import dao.CuentaProveedoresDao;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.Iterator;
import javax.swing.JDialog;
import javax.swing.JOptionPane;
import javax.swing.SwingConstants;
import javax.swing.table.DefaultTableModel;
import modelo.CuentaProveedor;
import modelo.Proveedor;

/**
 *
 * @author Cristian Perez
 */
public class CuentaProveedores extends javax.swing.JDialog {

    DefaultTableModel modeloCuentaProv = new DefaultTableModel();
    ArrayList<Object> listaAuxiliar;
    Proveedor auxProv;

    /** Creates new form CuentaProveedores */
    public CuentaProveedores(JDialog parent, boolean modal) {
        super(parent, modal);
        initComponents();

        modeloCuentaProv = (DefaultTableModel) jTable1.getModel();
        jTable1.setModel(modeloCuentaProv);
        estructurarTabla();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        lblCodProv = new javax.swing.JLabel();
        txtCodigo = new javax.swing.JTextField();
        lblRazSocial = new javax.swing.JLabel();
        txtRazonSocial = new javax.swing.JTextField();
        jPanel3 = new javax.swing.JPanel();
        jPanel4 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jPanel5 = new javax.swing.JPanel();
        lblDebe = new javax.swing.JLabel();
        lblHaber = new javax.swing.JLabel();
        lblValorDebe = new javax.swing.JLabel();
        lblValorHaber = new javax.swing.JLabel();
        lblValorSaldo = new javax.swing.JLabel();
        lblSald = new javax.swing.JLabel();
        btnEliminarTrans = new javax.swing.JButton();
        btnRegPago = new javax.swing.JButton();
        btnRegCompra = new javax.swing.JButton();
        btnSalir = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Estado de Cuenta");
        addWindowFocusListener(new java.awt.event.WindowFocusListener() {
            public void windowGainedFocus(java.awt.event.WindowEvent evt) {
                formWindowGainedFocus(evt);
            }
            public void windowLostFocus(java.awt.event.WindowEvent evt) {
            }
        });

        lblCodProv.setFont(new java.awt.Font("Tahoma", 1, 12));
        lblCodProv.setText("Codigo:");

        txtCodigo.setEditable(false);
        txtCodigo.setFont(new java.awt.Font("Tahoma", 3, 11));
        txtCodigo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtCodigoActionPerformed(evt);
            }
        });

        lblRazSocial.setFont(new java.awt.Font("Tahoma", 1, 12));
        lblRazSocial.setText("Razon Social: ");

        txtRazonSocial.setEditable(false);
        txtRazonSocial.setFont(new java.awt.Font("Tahoma", 3, 11));
        txtRazonSocial.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtRazonSocialActionPerformed(evt);
            }
        });

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Detalles de Cuenta", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 11))); // NOI18N

        jPanel4.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));

        jTable1.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {},
                {},
                {},
                {}
            },
            new String [] {

            }
        ));
        jScrollPane1.setViewportView(jTable1);

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 641, Short.MAX_VALUE)
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 243, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Totales", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 11))); // NOI18N

        lblDebe.setFont(new java.awt.Font("Times New Roman", 1, 14));
        lblDebe.setText("Debe :");

        lblHaber.setFont(new java.awt.Font("Times New Roman", 1, 14));
        lblHaber.setText("Haber :");

        lblValorDebe.setFont(new java.awt.Font("Tahoma", 1, 18));
        lblValorDebe.setForeground(new java.awt.Color(102, 0, 102));

        lblValorHaber.setFont(new java.awt.Font("Tahoma", 1, 18));
        lblValorHaber.setForeground(new java.awt.Color(102, 0, 102));

        lblValorSaldo.setFont(new java.awt.Font("Tahoma", 1, 18));
        lblValorSaldo.setForeground(new java.awt.Color(102, 0, 102));

        lblSald.setFont(new java.awt.Font("Times New Roman", 1, 14));
        lblSald.setText("Saldo : ");

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addGap(99, 99, 99)
                .addComponent(lblDebe)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lblValorDebe, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(64, 64, 64)
                .addComponent(lblHaber)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lblValorHaber, javax.swing.GroupLayout.PREFERRED_SIZE, 57, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 122, Short.MAX_VALUE)
                .addComponent(lblSald)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lblValorSaldo, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(53, 53, 53))
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblDebe)
                    .addComponent(lblHaber)
                    .addComponent(lblValorHaber, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblValorDebe, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblValorSaldo, javax.swing.GroupLayout.DEFAULT_SIZE, 20, Short.MAX_VALUE)
                    .addComponent(lblSald, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        btnEliminarTrans.setFont(new java.awt.Font("Tahoma", 1, 11));
        btnEliminarTrans.setText("Eliminar Transaccion");
        btnEliminarTrans.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEliminarTransActionPerformed(evt);
            }
        });

        btnRegPago.setFont(new java.awt.Font("Tahoma", 1, 11));
        btnRegPago.setText("Registrar Pago");
        btnRegPago.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnRegPagoActionPerformed(evt);
            }
        });

        btnRegCompra.setFont(new java.awt.Font("Tahoma", 1, 11));
        btnRegCompra.setText("Registrar Compra");
        btnRegCompra.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnRegCompraActionPerformed(evt);
            }
        });

        btnSalir.setFont(new java.awt.Font("Tahoma", 1, 11));
        btnSalir.setText("Salir");
        btnSalir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSalirActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lblCodProv, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(txtCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(31, 31, 31)
                .addComponent(lblRazSocial, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(txtRazonSocial, javax.swing.GroupLayout.PREFERRED_SIZE, 288, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(133, Short.MAX_VALUE))
            .addComponent(jPanel3, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addGap(22, 22, 22)
                .addComponent(btnEliminarTrans)
                .addGap(18, 18, 18)
                .addComponent(btnRegPago, javax.swing.GroupLayout.PREFERRED_SIZE, 123, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(btnRegCompra, javax.swing.GroupLayout.DEFAULT_SIZE, 133, Short.MAX_VALUE)
                .addGap(83, 83, 83)
                .addComponent(btnSalir, javax.swing.GroupLayout.PREFERRED_SIZE, 123, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
            .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblCodProv)
                    .addComponent(txtCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblRazSocial)
                    .addComponent(txtRazonSocial, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnSalir, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnEliminarTrans, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnRegPago, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnRegCompra, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-715)/2, (screenSize.height-515)/2, 715, 515);
    }// </editor-fold>//GEN-END:initComponents

    private void txtRazonSocialActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtRazonSocialActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtRazonSocialActionPerformed

    private void txtCodigoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtCodigoActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtCodigoActionPerformed

    private void btnSalirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSalirActionPerformed
        // TODO add your handling code here:
        this.dispose();
    }//GEN-LAST:event_btnSalirActionPerformed

    private void btnEliminarTransActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEliminarTransActionPerformed
        // TODO add your handling code here:

        Connection conn = null;
        if (jTable1.getRowCount() == 0) {
            JOptionPane.showMessageDialog(this, "No existen transacciones de cuenta para eliminar!!!", "Error", JOptionPane.INFORMATION_MESSAGE);
        }
        else if (jTable1.getSelectedRowCount() == 0){
            JOptionPane.showMessageDialog(this, "No ha seleccionado ninguna transaccion para eliminar...", "Error", JOptionPane.INFORMATION_MESSAGE);
        }
        else if (jTable1.getSelectedRowCount() < 2 ) {
            int rta = JOptionPane.showConfirmDialog(this,
                                        "Esta seguro de eliminar la transaccion de cuenta ?",
                                        "Eliminar",
                                        JOptionPane.YES_NO_OPTION);

            // Si no desea borrarlo, entonces no lo borra
            if(rta == JOptionPane.NO_OPTION) {
                return;
            }
            try {
                conn = AdministradorDeConexiones.obtenerConexion();
                //Le pedimos a la listaAuxiliar el articulo que vamos a borrar
                CuentaProveedor cuenta = (CuentaProveedor) listaAuxiliar.get(jTable1.getSelectedRow());
                //Eliminamos el item de la mesa, se borra de la base de datos
                CuentaProveedoresDao.getInstance().eliminar(conn, cuenta.getId());
                listarCuentasProv();
            }
            catch(Exception e) {e.printStackTrace();}

        }
    }//GEN-LAST:event_btnEliminarTransActionPerformed

    private void formWindowGainedFocus(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowGainedFocus
        // TODO add your handling code here:
        lblValorDebe.setHorizontalAlignment(SwingConstants.RIGHT);
        lblValorHaber.setHorizontalAlignment(SwingConstants.RIGHT);
        lblValorSaldo.setHorizontalAlignment(SwingConstants.RIGHT);
        listarCuentasProv();
        calcularSaldos();
    }//GEN-LAST:event_formWindowGainedFocus

    private void btnRegPagoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRegPagoActionPerformed
        // TODO add your handling code here:
        AltaCuentaProveedores ventaCuentaProv = new AltaCuentaProveedores(this, true);
        /**
         * Para identificar el tipo de operacion (Pago o Compra) en la ventana AltaCuentaProveedores
         * le pasamos un numero. Si le pasamos el numero 1 se trata de un pago y si le pasamos el 2
         * se trata de una compra
         */
        ventaCuentaProv.cargarDatosVentana(auxProv, 1);
        ventaCuentaProv.setVisible(true);
    }//GEN-LAST:event_btnRegPagoActionPerformed

    private void btnRegCompraActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRegCompraActionPerformed
        // TODO add your handling code here:
        AltaCuentaProveedores ventaCuentaProv = new AltaCuentaProveedores(this, true);
        /**
         * Para identificar el tipo de operacion (Pago o Compra) en la ventana AltaCuentaProveedores
         * le pasamos un numero. Si le pasamos el numero 1 se trata de un pago y si le pasamos el 2
         * se trata de una compra
         */
        ventaCuentaProv.cargarDatosVentana(auxProv, 2);
        ventaCuentaProv.setVisible(true);
    }//GEN-LAST:event_btnRegCompraActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnEliminarTrans;
    private javax.swing.JButton btnRegCompra;
    private javax.swing.JButton btnRegPago;
    private javax.swing.JButton btnSalir;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    private javax.swing.JLabel lblCodProv;
    private javax.swing.JLabel lblDebe;
    private javax.swing.JLabel lblHaber;
    private javax.swing.JLabel lblRazSocial;
    private javax.swing.JLabel lblSald;
    private javax.swing.JLabel lblValorDebe;
    private javax.swing.JLabel lblValorHaber;
    private javax.swing.JLabel lblValorSaldo;
    private javax.swing.JTextField txtCodigo;
    private javax.swing.JTextField txtRazonSocial;
    // End of variables declaration//GEN-END:variables

    public void mostrarEstadoCuenta(Proveedor prov) {
        auxProv = prov;
        txtCodigo.setText(String.valueOf(auxProv.getId()));
        txtRazonSocial.setText(prov.getRazSocial());
        listarCuentasProv();
        calcularSaldos();
    }

    private void estructurarTabla() {
        modeloCuentaProv.addColumn("FECHA");
        modeloCuentaProv.addColumn("COMPROBANTE");
        modeloCuentaProv.addColumn("DEBE");
        modeloCuentaProv.addColumn("HABER");

        jTable1.getColumnModel().getColumn(0).setPreferredWidth(100);
        jTable1.getColumnModel().getColumn(1).setPreferredWidth(300);
        jTable1.getColumnModel().getColumn(2).setPreferredWidth(100);
        jTable1.getColumnModel().getColumn(3).setPreferredWidth(100);
    }

    public void listarCuentasProv() {
        Connection conn = null;
        try {
            conn = AdministradorDeConexiones.obtenerConexion();
            //Recuperamos todos los articulos de la tabla de Articulos
            listaAuxiliar = null;
            listaAuxiliar = CuentaProveedoresDao.getInstance().getCuentasProv(conn, auxProv.getId());
            this.vaciarModeloCuenta();
            this.cargarModeloCuenta();
        }
        catch(Exception e) {e.printStackTrace();}
    }

    private void vaciarModeloCuenta() {
        modeloCuentaProv.setRowCount(0);
    }

     private void cargarModeloCuenta() {
        Iterator iteraCuentaProv = listaAuxiliar.iterator();
            while (iteraCuentaProv.hasNext()) {
                String[] arregloCuentaProv = new String[4];
                //Obtenemos cada cuenta de la lista
                CuentaProveedor cuentaProv = (CuentaProveedor) iteraCuentaProv.next();
                arregloCuentaProv[0] = cuentaProv.getFecha();
                arregloCuentaProv[1] = cuentaProv.getComprobante();
                arregloCuentaProv[2] = String.valueOf(cuentaProv.getDebe());
                arregloCuentaProv[3] = String.valueOf(cuentaProv.getHaber());
               //Agregamos el arreglo al modelo
                modeloCuentaProv.addRow(arregloCuentaProv);
            }
    }

    private void calcularSaldos() {
        Connection conn = null;
        try {
            conn = AdministradorDeConexiones.obtenerConexion();
            float deb = CuentaProveedoresDao.getInstance().calcularDebe(conn, auxProv.getId());
            float hab = CuentaProveedoresDao.getInstance().calcularHaber(conn, auxProv.getId());
            lblValorDebe.setText(String.valueOf(deb));
            lblValorHaber.setText(String.valueOf(hab));
            lblValorSaldo.setText(String.valueOf(deb-hab));
        }catch(Exception e) {e.printStackTrace();}
    }

}
